ChunkBy

sealed interface ChunkBy

Smooths text/reasoning streaming output by buffering until a chunk boundary, then releasing complete chunks with a configurable delay.

Mirrors v6's smoothStream. Critical UX helper for on-device models (LiteRT-LM on Android) that emit raw tokens fast enough to feel jittery — break by word boundaries, sleep delayMs between chunks, the chat surface gets natural reading rhythm.

Three chunking strategies:

Non-text events (tool calls, step-finish, etc.) pass through immediately without delay so the loop logic isn't slowed down.

Inheritors

Types

Link copied to clipboard
data object Line : ChunkBy
Link copied to clipboard
data class Pattern(val regex: Regex) : ChunkBy
Link copied to clipboard
data object Word : ChunkBy